<template>
  <div class="tree">
    <div class="trees new-tree">
      <a-tree v-if="treeData.length" blockNode :treeData="treeData" :defaultExpandAll="true" show-icon show-line @select="handleSelectIndex">
        <template #switcherIcon="{ expanded }"><i class="iconfont" :class="expanded ? 'icon-shouqi' : 'icon-zhankai'"></i></template>
        <template #title="{ dataRef, expanded, isLeaf }">
          <i class="iconfont icon-wenjian ico-file" v-if="isLeaf"></i>
          <i v-else class="iconfont ico-file" :class="expanded ? 'icon-wenjiandakai' : 'icon-wenjianguanbi'"></i>
          <span class="node-title">{{ dataRef.title }}</span>
        </template>
        <template #icon="item">
          <template v-if="item.scopedSlots.title == 'custom1'">
            <div class="custom-content">
              <div class="icons">
                <a-popover placement="top" overlayClassName="ztree-pop-black">
                  <template #content>
                    <p>编辑</p>
                  </template>
                  <span class="icon-wrap" @click="handelEdit(item, 1)">
                    <i class="iconfont icon-bianji cl-blue"></i>
                  </span>
                </a-popover>
                <a-popover placement="top" overlayClassName="ztree-pop-black">
                  <template #content>
                    <p>新增</p>
                  </template>
                  <span class="icon-wrap" @click="handelAdd(item)">
                    <i class="iconfont icon-tianjia cl-green"></i>
                  </span>
                </a-popover>
                <a-popover placement="top" overlayClassName="ztree-pop-black">
                  <template #content>
                    <p>删除</p>
                  </template>
                  <span class="icon-wrap" @click="handelsc(item)">
                    <i class="iconfont icon-shanchu cl-red"></i>
                  </span>
                </a-popover>
              </div>
            </div>
          </template>
          <template v-else-if="item.scopedSlots.title == 'custom2'">
            <div class="custom-content">
              <div class="icons">
                <a-popover placement="top" overlayClassName="ztree-pop-black">
                  <template #content>
                    <p>编辑</p>
                  </template>
                  <span class="icon-wrap" @click="handelEdit(item, 2)">
                    <i class="iconfont icon-bianji cl-blue"></i>
                  </span>
                </a-popover>
                <a-popover placement="top" overlayClassName="ztree-pop-black">
                  <template #content>
                    <p>新增</p>
                  </template>
                  <span class="icon-wrap" @click="handelAdd(item)">
                    <i class="iconfont icon-tianjia cl-green"></i>
                  </span>
                </a-popover>
                <a-popover placement="top" overlayClassName="ztree-pop-black">
                  <template #content>
                    <p>删除</p>
                  </template>
                  <span class="icon-wrap" @click="handelsc(item)">
                    <i class="iconfont icon-shanchu cl-red"></i>
                  </span>
                </a-popover>
              </div>
            </div>
          </template>
          <template v-else>
            <div class="custom-content">
              <div class="icons">
                <a-popover placement="top" overlayClassName="ztree-pop-black">
                  <template #content>
                    <p>编辑</p>
                  </template>
                  <span class="icon-wrap" @click="handelEdit(item, 3)">
                    <i class="iconfont icon-bianji cl-blue"></i>
                  </span>
                </a-popover>
                <a-popover placement="top" overlayClassName="ztree-pop-black">
                  <template #content>
                    <p>删除</p>
                  </template>
                  <span class="icon-wrap" @click="handelsc(item)">
                    <i class="iconfont icon-shanchu cl-red"></i>
                  </span>
                </a-popover>
              </div>
            </div>
          </template>
        </template>
      </a-tree>
    </div>
  </div>




  <a-modal centered v-model:open="openmodel" width="500px" title="一级指标" destroyOnClose @ok="handleOk" @cancel="handleOk" ok-text="确认" cancel-text="取消">
    <div class="top_jia">
      <div class="label">
        <span style="color: red">*</span> 指标名称：
      </div>
      <a-input placeholder="请输入" v-model:value="value" />
    </div>
  </a-modal>
</template>

<script setup lang="ts">
import { ref, createVNode } from 'vue'
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import { Modal } from 'ant-design-vue';


const treeData = ref([
  {
    "scopedSlots": {
      "title": "custom1"
    },
    "children": [
      {
        "code": "1",
        "scopedSlots": {
          "title": "custom2"
        },
        "level": "一级",
        "children": [
          {
            "code": "1-1",
            "scopedSlots": {
              "title": "custom3"
            },
            "level": "二级",
            "title": "环卫设施(1)",
            "key": 48
          },
          {
            "code": "1-2",
            "scopedSlots": {
              "title": "custom3"
            },
            "level": "二级",
            "title": "垃圾处理能力(3)",
            "key": 49
          },
          {
            "code": "1-3",
            "scopedSlots": {
              "title": "custom3"
            },
            "level": "二级",
            "title": "道路保洁(3)",
            "key": 50
          },
          {
            "code": "1-4",
            "scopedSlots": {
              "title": "custom3"
            },
            "level": "二级",
            "title": "建筑垃圾监管(2)",
            "key": 51
          },
          {
            "code": "1-5",
            "scopedSlots": {
              "title": "custom3"
            },
            "level": "二级",
            "title": "市容环境卫生公众参与(1)",
            "key": 52
          },
          {
            "code": "1-6",
            "scopedSlots": {
              "title": "custom3"
            },
            "level": "二级",
            "title": "现场评价（干净）(7)",
            "key": 53
          }
        ],
        "title": "干净(6)",
        "key": 43
      },
      {
        "code": "2",
        "scopedSlots": {
          "title": "custom2"
        },
        "level": "一级",
        "children": [
          {
            "code": "2-1",
            "scopedSlots": {
              "title": "custom3"
            },
            "level": "二级",
            "title": "绿地服务能力(7)",
            "key": 54
          },
          {
            "code": "2-2",
            "scopedSlots": {
              "title": "custom3"
            },
            "level": "二级",
            "title": "道路养护(1)",
            "key": 55
          },
          {
            "code": "2-3",
            "scopedSlots": {
              "title": "custom3"
            },
            "level": "二级",
            "title": "城市照明(2)",
            "key": 56
          },
          {
            "code": "2-4",
            "scopedSlots": {
              "title": "custom3"
            },
            "level": "二级",
            "title": "街道景观效果(1)",
            "key": 57
          },
          {
            "code": "2-5",
            "scopedSlots": {
              "title": "custom3"
            },
            "level": "二级",
            "title": "现场评价（整洁）(4)",
            "key": 58
          }
        ],
        "title": "整洁(5)",
        "key": 44
      },
      {
        "code": "3",
        "scopedSlots": {
          "title": "custom2"
        },
        "level": "一级",
        "children": [
          {
            "code": "3-1",
            "scopedSlots": {
              "title": "custom3"
            },
            "level": "二级",
            "title": "道路设施(4)",
            "key": 59
          },
          {
            "code": "3-2",
            "scopedSlots": {
              "title": "custom3"
            },
            "level": "二级",
            "title": "社区公共服务设施(6)",
            "key": 60
          },
          {
            "code": "3-3",
            "scopedSlots": {
              "title": "custom3"
            },
            "level": "二级",
            "title": "交通设施(4)",
            "key": 61
          },
          {
            "code": "3-4",
            "scopedSlots": {
              "title": "custom3"
            },
            "level": "二级",
            "title": "交通能力与秩序(3)",
            "key": 62
          },
          {
            "code": "3-5",
            "scopedSlots": {
              "title": "custom3"
            },
            "level": "二级",
            "title": "街区活力(1)",
            "key": 63
          },
          {
            "code": "3-6",
            "scopedSlots": {
              "title": "custom3"
            },
            "level": "二级",
            "title": "现场评价（有序）(6)",
            "key": 64
          }
        ],
        "title": "有序(6)",
        "key": 45
      },
      {
        "code": "4",
        "scopedSlots": {
          "title": "custom2"
        },
        "level": "一级",
        "children": [
          {
            "code": "4-1",
            "scopedSlots": {
              "title": "custom3"
            },
            "level": "二级",
            "title": "信息化水平(2)",
            "key": 65
          },
          {
            "code": "4-2",
            "scopedSlots": {
              "title": "custom3"
            },
            "level": "二级",
            "title": "问题处置及诉求响应(3)",
            "key": 66
          },
          {
            "code": "4-3",
            "scopedSlots": {
              "title": "custom3"
            },
            "level": "二级",
            "title": "志愿服务水平(2)",
            "key": 67
          },
          {
            "code": "4-4",
            "scopedSlots": {
              "title": "custom3"
            },
            "level": "二级",
            "title": "组织保障(4)",
            "key": 68
          },
          {
            "code": "4-5",
            "scopedSlots": {
              "title": "custom3"
            },
            "level": "二级",
            "title": "满意度评价(2)",
            "key": 69
          },
          {
            "code": "4-6",
            "scopedSlots": {
              "title": "custom3"
            },
            "level": "二级",
            "title": "治理行动(1)",
            "key": 70
          }
        ],
        "title": "群众满意度(6)",
        "key": 46
      }
    ],
    "title": "城市管理监督(70)",
    "key": "1"
  }
]);

const openmodel = ref(true)
const value = ref("")

const handleOk = () => {
  openmodel.value = false;
}



const handleSelectIndex = () => {

}
const handelEdit = (item1, item2) => {

}
const handelsc = (item) => {
  Modal.confirm({
    title: '是否确认删除',
    icon: createVNode(ExclamationCircleOutlined),
    content: '删除后无法恢复',
    okText: '确认',
    cancelText: '取消',
  });
}
const handelAdd = (item: any) => {
  Modal.confirm({
    title: '新增',
    icon: createVNode(ExclamationCircleOutlined),
    content: createVNode('div', { style: 'color:red;' }, '新增字段'),
    onOk() {
      console.log('OK');
      treeData.value[0].children[0].children.unshift({
        "code": "1-11",
        "scopedSlots": {
          "title": "custom3"
        },
        "level": "二级",
        "title": "新增环卫设施(1)",
        "key": 1111
      },)
    },
    onCancel() {
      console.log('Cancel');
    },
    class: 'test',
  });

}
</script>

<style lang="scss" scoped>
.tree {
  width: 100%;
  height: 650px;
  overflow-y: auto;
  background-color: rgba(250, 250, 250, 1);
  padding: 15px;

  .trees {
    width: 400px;
    height: 100%;

  }



}

.top_jia {
  display: flex;
  align-items: center;
  margin-bottom: 20px;

  .label {
    width: 110px;
    color: rgba(0, 0, 0, 0.85);
  }

  .label-top {
    width: 70px;
  }

  .ant-select {
    flex: 1;
  }

  .sc_btn {
    width: 140px;
    height: 32px;
    border-radius: 2px;
    border: 1px solid blue;
    color: blue;
    justify-content: center;
    display: flex;
    align-items: center;
    margin-left: 20px;
    cursor: pointer;

    i {
      margin-right: 5px;
    }
  }
}
</style>

